from django.db import models

# from apps.users.models import User, UserAddress
# from apps.users.models import Order,UserAddress
# from apps.goods.models import HuaweiGoods
# from cassoapi.cassoapi.apps.users.models import User, UserAddress
# from cassoapi.cassoapi.apps.goods.models import HuaweiGoods
# from users.models import User,UserAddress
# from goods.models import HuaweiGoods
# from .apps.users.models import User, UserAddress
# from .apps.goods.models import HuaweiGoods
# from users.models import User, UserAddress
# from goods.models import HuaweiGoods
from huaweiSpider.华为手机系列 import rongyao

# from users import models
from users.models import User, UserAddress
from goods.models import HuaweiGoods
from datetime import datetime, timedelta

# Create your models here.


class Order(models.Model):
    ORDER_STATUS = (
        ("0", "new"),
        ("1", "notpaid"),
        ("2", "paid"),
        ("3", "ship"),
        ("4", "finish"),
    )
    objects = models.Manager()
    ordernum = models.CharField("订单号", max_length=15)
    goods = models.ForeignKey(
        HuaweiGoods, related_name="ordergoods", on_delete=models.CASCADE
    )
    owner = models.ForeignKey(User, related_name="orderuser", on_delete=models.CASCADE)
    status = models.CharField("订单状态", choices=ORDER_STATUS, default="0", max_length=15)
    goodsnums = models.IntegerField("购买数量")
    create_time = models.DateTimeField("创建时间", auto_now_add=True)
    deliveraddress = models.ForeignKey(
        UserAddress,
        verbose_name=("收货地址"),
        on_delete=models.CASCADE,
        blank=True,
        null=True,
    )

    class Meta:
        verbose_name = "订单"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.ordernum


class Favorite(models.Model):
    objects = models.Manager()
    goods = models.ForeignKey(
        HuaweiGoods, on_delete=models.CASCADE, related_name="favgoods"
    )
    owner = models.ForeignKey(
        User, on_delete=models.CASCADE, related_name="favgoodsuser"
    )
    add_time = models.DateTimeField("添加时间", auto_now_add=True)

    class Meta:
        verbose_name = "用户收藏"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.goods


class ServerCenter(models.Model):
    SERVER_TYPE = (
        ("1", "退货退款"),
        ("2", "物流延迟"),
        ("3", "以旧换新"),
        ("4", "期内保修"),
        ("5", "技术求救"),
        ("6", "其他类型"),
    )
    SERVER_STATUS = (("1", "处理中"), ("2", "完结"), ("3", "后续处理"))
    SERVER_RANGE = (
        ("0", "暂无评分"),
        ("1", "0.5"),
        ("2", "1"),
        ("3", "1.5"),
        ("4", "2"),
        ("5", "2.5"),
        ("6", "3"),
        ("7", "3.5"),
        ("8", "4"),
        ("9", "4.5"),
        ("10", "5"),
    )
    objects = models.Manager()
    order = models.ForeignKey(
        Order, on_delete=models.CASCADE, related_name="servercenter"
    )
    add_time = models.DateTimeField("提交时间", auto_now_add=True)
    servernumber = models.CharField("事项单号", max_length=25)
    owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name="提交用户")
    details = models.CharField("事项详细", max_length=300)
    servertype = models.CharField(
        "事项类型", choices=SERVER_TYPE, default="6", max_length=15
    )
    finishitime = models.DateTimeField(
        "完成时间", default=(datetime.now() + timedelta(days=3))
    )
    serverstatus = models.CharField(
        "事件状态", choices=SERVER_STATUS, max_length=15, default="1"
    )
    solution = models.CharField("解决方案", max_length=200)
    serverrate = models.CharField(
        "服务评分", choices=SERVER_RANGE, max_length=3, default="0"
    )
    ratemessage = models.CharField("评论留言", max_length=250, blank=True, null=True)
    outoftime = models.BooleanField("超时", default=False)
    backupsolution = models.CharField("后续方案", max_length=250, blank=True, null=True)

    class Meta:
        verbose_name = "售后服务"
        verbose_name_plural = verbose_name
